import { View,Image} from "@tarojs/components";
import {useEffect, useState} from "react";
import {getCurrentInstance} from "@tarojs/runtime";
import {AtButton} from "taro-ui";
import Taro from "@tarojs/taro";
import background from "../../assets/background.jpg";
import {GlobalFooter} from "../../components/GlobalFooter";
import "./index.scss";
import results from '../../data/result.json'
import scoreResults from "../../utils/scoreUtil";
import questions from "../../data/question.json";


export default () => {
  const [result,setResult] = useState()
  useEffect(() => {
    const { router } = getCurrentInstance()
    // @ts-ignore
    setResult(scoreResults(JSON.parse(decodeURIComponent(router.params.data)),questions,results)??results[0]);
  }, []);



  return (
    <View className="resultPage">
      <View className="at-article__h1 title">{result?.resultName}</View>
      <View className="at-article__h2 subTitle">{result?.resultDesc}</View>
      <AtButton
        type="primary"
        size="normal"
        className="enterBtn"
        circle
        onClick={() => {
          Taro.reLaunch({
            url: "/pages/index/index",
          });
        }}
      >
        返回主页
      </AtButton>
      <Image src={background} style={{ width: "100%",minHeight:"100vh" }} mode="aspectFit" />
      <GlobalFooter />

    </View>
  );
};
